﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using PersonalHealth.Data.Model;
using UI.Comm.Controls;

namespace PersonHealth
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : PMWindow
    {
        //是否为外部调用
        bool isExternal = false;

        /// <summary>
        /// 只能被当前工程启动
        /// </summary>
        public MainWindow()
        {
            MessageBox.Show("非法登陆");
            App.Current.Shutdown();
            return;
            InitializeComponent();
            isExternal = false;
        }

        Action onLogout;
        /// <summary>
        /// 只能被外部工程启动
        /// </summary>
        public MainWindow(MeasureUser user, Action onLogout)
        {
            InitializeComponent();
            isExternal = true;
            this.onLogout = onLogout;
            AppData.User = user;
            this.ContentFrame.Source = new Uri("View/PersonPage.xaml", UriKind.RelativeOrAbsolute);
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (isExternal)
            {
                if (ContentFrame.NavigationService.Content is PersonHealth.View.PersonPage)
                    onLogout();
                else
                    ContentFrame.NavigationService.GoBack();
            }
            else
            {
                ContentFrame.NavigationService.GoBack();
            }
        }

        private void ContentFrame_Navigated(object sender, NavigationEventArgs e)
        {
            if (isExternal)
            {
                BackBtn.Visibility = Visibility.Visible;
            }
            else
            {
                BackBtn.Visibility = ContentFrame.NavigationService.CanGoBack ? Visibility.Visible : Visibility.Collapsed;
            }
        }


    }
}
